<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/main.css">
    <link rel="stylesheet" href="../css/jquery-ui.css">
    <link href="../css/bootstrap.css" rel="stylesheet" type="text/css" />
    <title></title>
    <style>
        th{text-align: center;}
        .m0{margin: 0px;}
        #dialogLevel2Div{
            margin: 0px;
            padding: 0px;;
        }
        .title{
            height: 37px;
            line-height: 37px;
            background: url('../images/box_top.png') 0px 0px repeat-x;
        }
    </style>
</head>
<body>
<div class="box">
    <div class="box_border" style="border-bottom: none;">
        <div class="title" onclick="toggleLevel(1)"><b class="pl15">财务人员管理</b></div>
        <div id="divLevel1" class="mt10">
            <div class="box span9 oh" style="margin-left: auto; margin-right: auto">
                <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" style="table-layout:fixed; font-size:1.2rem">
                    <tr >
                        <th >序号</th>
                        <th>账号</th>
                        <th>姓名</th>
                        <th>权限</th>
                        <th>可选操作</th>
                    </tr>
                    <tbody id="tableLevel1">

                    </tbody>
                </table>
                <div class="page mt10 fl">
                    <a class="ext_btn add mt10" onclick="addFinanceLeader()" ><span class="add" ></span>添加财务人员</a>
                    <!--<a class="ext_btn del mt10" ><span class="del" ></span>删除全部</a>-->
                </div>
                <div id="dialogLevel1Div" title="" style="display: none;">
                    <form name="from1" >
                        <div class="pb10 mb15 disabled "> <div style="display: inline-block;width:82px;text-align: right;">用户名称:</div>
                            <input type="text" name="FinanceUserName" class="input-text lh30 ml disabled" id="FinanceUserName" size="23"  readonly><span style="color:red;font-size: 20px;">&nbsp;*</span>
                            <input type="text" name="FinanceUserId" class="input-text lh30 ml disabled" id="FinanceUserId" size="23" style="display: none;" readonly>
                        </div>
                        <div class="pb10 mb15"> <div style="display: inline-block;width:82px;text-align: right;" >权限:</div>
                            <select name="FinanceSelectSection" id="FinanceSelectSection" class="select ml" style="width: 175px;" >
                                <option value="1">财务管理</option>
                            </select>
                        </div>
                    </form>
                </div >
                <div id="dialogLevel1AddDiv" title="" style="display: none;">
                    <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" style="table-layout:fixed; font-size:1.2rem">
                        <tr>
                            <th style="width: 8%;">序号</th>
                            <th>账号</th>
                            <th>姓名</th>
                            <th style="width: 15%;">可选操作</th>
                        </tr>
                        <tbody id="Level1AddTable">
                        </tbody>
                    </table>
                    <div class="page  fl" style="margin-top: -8px; margin-bottom: 0;">
                        <div class="pagination" style="margin-bottom: 0;">
                            <input type="text" id="level1SearchText" name="search" class="input-text lh30" size="20">
                            <input type="button" value="搜索" class="ext_btn ext_btn_submit" onclick="FinanceaddSearch()">
                            <input type="button" value="全部人员"  class="ext_btn ext_btn_submit" onclick="addFinanceAllUser()">
                        </div>
                    </div>
                    <div class="page  fr" style="margin-top: -10px; margin-bottom: 0;">
                        <div class="pagination" style="margin-bottom: 0;">
                            <ul id="addLevel1Ul">
                                <li class="first-child " id="addLevel1Li1"><a onclick="firstLastAddLevel1Page(0)">首页</a></li>
                                <li class="" id="addLevel1Li2"><a onclick="upDownAddLevel1Page(-1)">上一页</a></li>
                                <li class="" id="addLevel1Li3"><a onclick="upDownAddLevel1Page(1)">下一页</a></li>
                                <li class="last-child " id="addLevel1Li4"><a onclick="firstLastAddLevel1Page(1)">末页</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="info" style="display:none;text-align: center;"></div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/config.js"></script>
<script type="text/javascript">
    $(function () {
        GetFinanceAdminInfo();
    });

    //消息提示框
    function dialogInfo(e){
        $("#info").html(e).dialog({
            resizable: false,
            title: "信息",
            modal: true,
            buttons: {
                '确定': function () {
                    $("#info").dialog("close");
                }
            }
        });
        setTimeout('closeDialogInfo()',1000);
    }
    //关闭消息提示框
    function closeDialogInfo(){
        $("#info").dialog('close');
    }

    //**************************************************************
    //加载表格
    function CreateTable(tableData){
        var i=0;
        var tableLevel1=$("#tableLevel1");
        tableLevel1.empty();
        for(;i<tableData.length;i++){
            tableLevel1.append(
                '<tr><td class="td_center" >' +(i+1) + '</td>'+
                '<td class="td_center  " style="display: none;" >' + tableData[i]['Id'] + '</td>'+
                '<td class="td_center  " >' + tableData[i]['user_ID'] + '</td>'+
                '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                '<td class="td_center  " >' + tableData[i]['finance_power'] + '</td>'+
                '<td class="td_center">'+
                '<a class="ext_btn modify" onclick="editFinance(this)" ><span class="modify" ></span>编辑</a><a class="ext_btn del" onclick="FinanceAdminDeleteData('+tableData[i]['user_ID']+')" ><span class="del" ></span>删除</a></td></tr>'
            );
        }
    }
    //获取当前页数据
    function GetFinanceAdminInfo(){
        var phpUrl=url+'admin/FinanceAdmin/GetFinanceAdminInfo.php';
        $.ajax({
            url:phpUrl,
            type:'POST',
            async:true,
            success: function (data) {
                data=JSON.parse(data);
                if(data.state==1){
                    CreateTable(data.data);
                }
            }
        });
    }
    //删除level1
    function FinanceAdminDeleteData(e){

        var phpUrl=url+'admin/FinanceAdmin/FinanceAdminDeleteData.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{user_ID:e},
            success: function (data) {
                data=JSON.parse(data);
                if(data.state==1) {
                    GetFinanceAdminInfo()
                    dialogInfo("删除成功！");
                }
                else
                    dialogInfo("删除失败！");
            }
        });
    }

    //添加领导
    function addFinanceLeader(){
        $("#dialogLevel1AddDiv").dialog({
            position: { my: "top-300px", at: "center", of: window  } ,
            title:'添加财务管理人员',
            resizable:false,
            width:600
        });
        addFinanceGetPageCount();
        addFinanceGetUserLimit(0,10);
    }
    var addLevel1CurPage=0;
    var addLevel1PageCounts=1;
    //添加领导之加载人员
    function addFinanceGetUserLimit(n,m){
        var phpUrl=url+'admin/FinanceAdmin/FinanceAddGetUserLimit.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{n:n,m:m},
            success: function (data) {
                data=JSON.parse(data);
                if(data.state==1){
                    var tableData=data.data;
                    var Level1AddTable=$("#Level1AddTable");
                    Level1AddTable.empty();
                    for(var i=0;i<tableData.length;i++){
                        Level1AddTable.append(
                            '<tr><td class="td_center" >' +(i+1) + '</td>'+
                            '<td class="td_center  " >' + tableData[i]['user_ID'] + '</td>'+
                            '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                            '<td class="td_center"><a class="ext_btn add" onclick="addFinanceToLeader(this)" ><span class="add" ></span>添加</a></td></tr>'
                        );
                    }
                }
            }
        });
    }
    //添加level1领导之加获取人员数量
    function addFinanceGetPageCount(){
        var phpUrl=url+'admin/FinanceAdmin/FinanceAddGetPageCount.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:false,
            success: function (data) {
                data = JSON.parse(data);
                if (data.state == 1) {
                    addLevel1PageCounts = Math.ceil(data.pageCount/10);
                    if(addLevel1PageCounts<=1) {addLevel1PageCounts=1; $("#addLevel1Ul li").addClass("disabled") } else {$("#addLevel1Ul li").removeClass("disabled")}
                }
            }
        });
    }
    //添加level1领导之首尾页
    function firstLastAddLevel1Page(e){
        if(e==0) {
            addLevel1CurPage=0;
            $("#addLevel1Ul li").addClass("disabled");
            $("#addLevel1Li3").removeClass("disabled");
            $("#addLevel1Li4").removeClass("disabled");
        }
        else{
            addLevel1CurPage=addLevel1PageCounts-1;
            $("#addLevel1Ul li").addClass("disabled");
            $("#addLevel1Li1").removeClass("disabled");
            $("#addLevel1Li2").removeClass("disabled");
        }
        addFinanceGetUserLimit(addLevel1CurPage*10,10);
        if(addLevel1PageCounts<=1) {addLevel1PageCounts=1; $("#addLevel1Ul li").addClass("disabled")}
    }
    //添加level1领导之上下页
    function upDownAddLevel1Page(e){
        if(addLevel1CurPage>=0||addLevel1CurPage<=addLevel1PageCounts-1){
            if(e<0){
                if(addLevel1CurPage>0)  {
                    addLevel1CurPage--;
                    if(addLevel1CurPage>0) $("#addLevel1Ul li").removeClass("disabled");
                    else{
                        $("#addLevel1Ul li").removeClass("disabled");
                        $("#addLevel1Li1").addClass("disabled");
                        $("#addLevel1Li2").addClass("disabled");
                    }
                }
            }else{
                if(addLevel1CurPage<addLevel1PageCounts-1) {
                    addLevel1CurPage++;
                    if(addLevel1CurPage<addLevel1PageCounts-1) $("#level1Ul li").removeClass("disabled");
                    else{
                        $("#addLevel1Ul li").removeClass("disabled");
                        $("#addLevel1Li3").addClass("disabled");
                        $("#addLevel1Li4").addClass("disabled");
                    }
                }
            }
            addFinanceGetUserLimit(addLevel1CurPage*10,10);
            if(addLevel1PageCounts<=1) {addLevel1PageCounts=1; $("#addLevel1Ul li").addClass("disabled")}
        }
    }
    //增加人员之搜索人员 level1SearchText
    function FinanceaddSearch(){
        var searchText=$("#level1SearchText").val();
        if(searchText!=''){
            $("#addLevel1Ul").hide();
            var phpUrl=url+'admin/FinanceAdmin/FinanceAddSearch.php';
            $.ajax({
                url:phpUrl,
                type:"POST",
                async:true,
                data:{searchText:searchText},
                success: function (data) {
                    data=JSON.parse(data);
                    if(data.state==1){
                        var tableData=data.data;
                        var Level1AddTable=$("#Level1AddTable");
                        Level1AddTable.empty();
                        for(var i=0;i<tableData.length;i++){
                            Level1AddTable.append(
                                '<tr><td class="td_center" >' +(i+1) + '</td>'+
                                '<td class="td_center  " >' + tableData[i]['user_ID'] + '</td>'+
                                '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                                '<td class="td_center"><a class="ext_btn add" onclick="addFinanceToLeader(this)" ><span class="add" ></span>添加</a></td></tr>'
                            );
                        }
                    }
                }
            });
        }
    }
    //增加人员之显示全部人员
    function addFinanceAllUser(){
        firstLastAddLevel1Page(0);
        $("#addLevel1Ul").show();
    }
    //添加level1领导之添加到部门

    function addFinanceToLeader(e){
        var thisTr=e.parentNode.parentNode;
        var thisUserId=thisTr.childNodes[1].innerHTML;
        var thisUserName=thisTr.childNodes[2].innerHTML;
        $("#FinanceUserId").val(thisUserId);
        $("#FinanceUserName").val(thisUserName);
            $("#dialogLevel1Div").dialog({
                width:320,
                resizable: false,
                title:'添加财务人员-'+thisUserName,
                modal: true,
                buttons:{
                    '取消': function () {
                        $("#dialogLevel1Div").dialog('close');
                    },
                    '保存': function () {
                        var FinancePower=$("#FinanceSelectSection").val();
                        var phpUrl=url+'admin/FinanceAdmin/FinanceAddInsert.php';
                        $.ajax({
                            url:phpUrl,
                            type:"POST",
                            async:true,
                            data:{user_ID:thisUserId,finance_power:FinancePower},
                            success: function (data) {
                                data=JSON.parse(data);
                                if(data.state==1) {
                                    $("#dialogLevel1Div").dialog('close');
                                    addFinanceGetPageCount();
                                    GetFinanceAdminInfo();
                                    firstLastAddLevel1Page(0);
                                    dialogInfo("保存成功！");
                                }
                                else dialogInfo("保存失败！");
                            }
                        });
                    }
                }
            });
    }
    //编辑level1某个部门的信息
    function editFinance(e){
        var thisTr=e.parentNode.parentNode;
        var thisUserId=thisTr.childNodes[1].innerHTML;
        var thisUserName=thisTr.childNodes[2].innerHTML;
        var thisUserPower=thisTr.childNodes[3].innerHTML;
        $("#FinanceUserId").val(thisUserId);
        $("#FinanceUserName").val(thisUserName);
        $("#FinanceSelectSection").val(thisUserPower);
        $("#dialogLevel1Div").dialog({
            width:320,
            resizable: false,
            title:'添加财务人员-'+thisUserName,
            modal: true,
            buttons:{
                '取消': function () {
                    $("#dialogLevel1Div").dialog('close');
                },
                '保存': function () {
                    var FinancePower=$("#FinanceSelectSection").val();
                    var phpUrl=url+'admin/FinanceAdmin/FinanceAddUpdate.php';
                    $.ajax({
                        url:phpUrl,
                        type:"POST",
                        async:true,
                        data:{user_ID:thisUserId,finance_power:FinancePower},
                        success: function (data) {
                            data=JSON.parse(data);
                            if(data.state==1) {
                                $("#dialogLevel1Div").dialog('close');
                                addFinanceGetPageCount();
                                GetFinanceAdminInfo();
                                firstLastAddLevel1Page(0);
                                dialogInfo("保存成功！");
                            }
                            else dialogInfo("保存失败！");
                        }
                    });
                }
            }
        });
    }
</script>
</html>